//
// Created by dxyinme on 2021/11/16.
//

#include "test_comm.h"
#include "FPStyle/loop.h"

class LoopTest : public TestComm {
  void SetUp() override {
    TestComm::SetUp();
  }

  void TearDown() override {
    TestComm::TearDown();
  }
};

using namespace FPStyle;


TEST_F(LoopTest, ForIndexTest) {
  int a[] = {0,1,2,3,4,5};
  ForIndex(0, 6, [&](int &index, Task<Control>& t) {
    std::cout << a[index] << "\n";
  });
}

TEST_F(LoopTest, ForIndexTest_Increment_2) {
  int a[] = {0,1,2,3,4,5};
  ForIndex(0, 6, [&](int &index, Task<Control>& t) {
    std::cout << a[index] << "\n";
  }, 2);
}

TEST_F(LoopTest, ForIndexTest_Break) {
  std::vector<int> v;
  ForIndex(0, 600, [&](int &index, Task<Control>& t) {
    IfElse(index == 300, [&] {
      t.ret = Control::BREAK;
      t.Done();
    },[&] {
      v.push_back(index);
    });
  });
  EXPECT_EQ(v.size(), 300);
}